package com.qianbei.common.loading;

import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.WindowManager;

import com.qianbei.R;
import com.qianbei.common.base.BaseActivity;
import com.qianbei.common.base.BaseApplication;

public class LoadingActivity extends BaseActivity {



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        showSplashView();
        showFromMessage();
    }

    private void parseNormalIntent(Intent intent) {
        showMainActivity(intent);
    }

    protected void onResume() {
        super.onResume();

        if (!BaseApplication.isBrowsLauch) {
            SharedPreferences userInfo = getSharedPreferences("user_info", 0);
            boolean isShowGuid = userInfo.getBoolean("isShowGuide", true);
            if (isShowGuid) {
                new Handler().postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        startActivity(new Intent(mContext, GuideActivity.class));
                        finish();
                    }
                }, 2000);
            } else {
                new Handler().postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        showMainActivity();
                    }
                }, 2000);

            }
        }

    }

    /**
     * 首次进入，打开欢迎界面
     */
    private void showSplashView() {
        getWindow().setBackgroundDrawableResource(R.drawable.loading);
    }

    private void showMainActivity() {
        showMainActivity(null);
    }

    private void showMainActivity(Intent intent) {
//        startActivity(GuideActivity.class);
        finish();
    }

    /**
     * 显示从短信跳转过来的内容
     */
    private void showFromMessage() {
        Intent intent = getIntent();
        String action = intent.getAction();

        if (Intent.ACTION_VIEW.equals(action)) {
            Uri uri = intent.getData();
            if (uri != null) {
                String scheme = uri.getScheme();
                String host = uri.getHost();
                String dataString = intent.getDataString();
                String newsId = uri.getQueryParameter("newsId");
                String path = uri.getPath();
                String path1 = uri.getEncodedPath();
                String queryString = uri.getQuery();
                Log.d("Alex", "scheme:" + scheme);
                Log.d("Alex", "host:" + host);
                Log.d("Alex", "dataString:" + dataString);
                Log.d("Alex", "newsId:" + newsId);
                Log.d("Alex", "path:" + path);
                Log.d("Alex", "path1:" + path1);
                Log.d("Alex", "queryString:" + queryString);

            }
        }
    }


}
